{layout name="layout/main" /}
{:breadcrumb(['个人中心:admin/profile/index', '二步验证'])}
{if empty($auth)}
<div class="row">
    <div class="col-lg-5">
        <div class="card">
            <div class="card-body">
                <form action="{:url('admin/profile/auth')}" method="post" class="input-form needs-validation" novalidate>
                    <input type="hidden" name="secret" value="{$secret}">
                    <div class="modal-body">
                        <div class="mb-3 row">
                            <label class="col-sm-3 col-form-label">密钥文本 <font color="red">*</font></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" value="{$secret}" readonly>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label class="col-sm-3 col-form-label">二维码</label>
                            <div class="col-sm-9">
                                <img src="https://api.qrserver.com/v1/create-qr-code/?data={$image}&size=200x200&ecc=M" class="img-fluid" alt="二维码">
                                <div class="form-text" style="color: red;">
                                    请妥善保存密钥或二维码，丢失后将无法找回！
                                </div>
                            </div>
                        </div>
                        <div class="mb-3 row">
                            <label for="code" class="col-sm-3 col-form-label">验证码 <font color="red">*</font></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="code" name="code" placeholder="输入6位验证码" autocomplete="off" required>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">开启二步验证</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $(function (){
        validation_form('.input-form', function (){
            location.reload();
        }); 
    });
</script>
{else /}
<div class="row">
    <div class="col-lg-5">
        <div class="card">
            <div class="card-body">
                <form action="{:url('admin/profile/close')}" method="post" class="input-form needs-validation" novalidate>
                    <div class="modal-body">
                        <div class="mb-3 row">
                            <label for="code" class="col-sm-3 col-form-label">验证码 <font color="red">*</font></label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" id="code" name="code" placeholder="输入6位验证码" autocomplete="off" required>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-danger">关闭二步验证</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script>
    $(function (){
        validation_form('.input-form', function (){
            location.reload();
        }); 
    });
</script>
{/if}